package exercise;

public class EX04_Q32 {
	
	// #32
	
	public static void main(String[] args) {
		long jumin = 8508251178414L;
		int key = 0;
		int total = 0;		
		
		// 123456
		// 123456/100000 => 1
		// 123456%(1*100000) => 23456
		
		// 23456/10000 => 2
		// 23456%(2*10000) => 3456
		
		// 3456/1000 => 3
		// 3456%(3*1000) => 456
		
		// 1 자리수
		key = (int)(jumin / 1000000000000L);
		total = total + (key*2);
		if (key > 0)
			jumin = jumin % (key*1000000000000L);
		
		// 2 자리수
		key = (int)(jumin / 100000000000L);
		total = total + (key*3);	
		if (key > 0)
			jumin = jumin % (key*100000000000L);
		
		// 3 자리수
		key = (int)(jumin / 10000000000L);
		total = total + (key*4);
		if (key > 0)
			jumin = jumin % (key*10000000000L);
		
		// 4 자리수
		key = (int)(jumin / 1000000000L);
		total = total + (key*5);
		if (key > 0)
			jumin = jumin % (key*1000000000L);		
	
		// 5 자리수
		key = (int)(jumin / 100000000L);
		total = total + (key*6);
		if (key > 0)
			jumin = jumin % (key*100000000L);
	
		// 6 자리수
		key = (int)(jumin / 10000000L);
		total = total + (key*7);
		if (key > 0)
			jumin = jumin % (key*10000000L);
		
		// 7 자리수
		key = (int)(jumin / 1000000L);
		total = total + (key*8);
		if (key > 0)
			jumin = jumin % (key*1000000L);
		
		// 8 자리수
		key = (int)(jumin / 100000L);
		total = total + (key*9);
		if (key > 0)
			jumin = jumin % (key*100000L);
		
		// 9 자리수
		key = (int)(jumin / 10000L);
		total = total + (key*2);
		if (key > 0)
			jumin = jumin % (key*10000L);
		
		// 10 자리수
		key = (int)(jumin / 1000L);
		total = total + (key*3);
		if (key > 0)
			jumin = jumin % (key*1000L);
		
		// 11 자리수
		key = (int)(jumin / 100L);
		total = total + (key*4);
		if (key > 0)
			jumin = jumin % (key*100L);
		
		// 12 자리수
		key = (int)(jumin / 10L);
		total = total + (key*5);
		if (key > 0)
			jumin = jumin % (key*10L);

		// 마지막 자리
		key = (int)(jumin / 1L);
		
		System.out.println(jumin);
		System.out.println(total);
		System.out.println(total%11);
		System.out.println(11-total%11);		
		
		
		if ((11-total%11)%10 == key) {
			System.out.println("ok");
		} else {
			System.out.println("no");
		}
		
		//System.out.println(Math.pow(10, 3));
		
		jumin = 8508251178414L;
		key = 0;
		total = 0;	
		
		for (int pow = 12, prime = 2; pow >= 1; --pow, ++prime) {
			long divider = (long)Math.pow(10, pow);
			if (prime > 9) prime = 2;
			key = (int)(jumin / divider);
			total = total + (key*(int)prime);
			if (key > 0)
				jumin = jumin % (key*divider);
		}
		
		key = (int)(jumin / 1L);
		
		System.out.println(jumin);
		System.out.println(total);
		System.out.println(total%11);
		System.out.println(11-total%11);				
		
		
		if ((11-total%11)%10 == key) {
			System.out.println("ok");
		} else {
			System.out.println("no");
		}
		
		
	}

} // EX04_Q32

class IdnoVO {
	public IdnoVO() {
	}
}
